package com.example.springboot1.api.sele;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

/**
 * @author ckj
 * @description TODO
 * @date 2022-09-01 10:34
 */


public class AutoAPi {
    public static void main(String[] args) {
        System.getProperties().setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe");
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("no-sandbox");//禁用沙盒
        //通过ChromeOptions的setExperimentalOption方法，传下面两个参数来禁止掉谷歌受自动化控制的信息栏
        chromeOptions.setExperimentalOption("useAutomationExtension", false);
        chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));

        ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
        chromeDriver.get("https://www.baidu.com/");
//        chromeDriver.manage().window().maximize();
//        chromeDriver.get("https://www.bilibili.com/");

        chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//        chromeDriver.findElementByLinkText("hao123").click();

//        WebElement userinput = chromeDriver.findElement(By.xpath("/html/body/div/form/div[3]/div/div[1]/input]"));
//        if (userinput != null) {
//            userinput.sendKeys("020218");
//        }
//        chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//        chromeDriver.quit();

//        chromeDriver.findElementById("kw").sendKeys("Selenium");
//        chromeDriver.findElementById("su").click();
//        chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement elementByXPath = chromeDriver.findElementByXPath("//input[@id='kw']");

        System.out.println(elementByXPath);

    }




}
